﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FCMS.Data;
using FCMS.Data.Infrastructure;
using FCMS.Entities;

namespace FCMS.Service
{
    public interface IUserService
    {
        IEnumerable<User> GetUsers();
        User GetUser(int id);
        void CreateUser(User category);
        void DeleteUser(int id);
        void SaveUser();
    }

    public class UserService : IUserService
    {
        private readonly IUserRepository userRepository;
        private readonly IUnitOfWork unitOfWork;

        public UserService()
        {
            var dataBaseFactory = new DatabaseFactory();
            this.userRepository = new UserRepository(dataBaseFactory);
            this.unitOfWork = new UnitOfWork(dataBaseFactory);
        }

        public UserService(IUserRepository userRepository, IUnitOfWork unitOfWork)
        {
            this.userRepository = userRepository;
            this.unitOfWork = unitOfWork;
        }

        public IEnumerable<User> GetUsers()
        {
            throw new NotImplementedException();
        }

        public User GetUser(int id)
        {
            return userRepository.GetById(id);
        }

        public void CreateUser(User user)
        {
            userRepository.Add(user);
            unitOfWork.Commit();
        }

        public void DeleteUser(int id)
        {
            userRepository.Delete(e => e.XX == "11");
            throw new NotImplementedException();
        }

        public void SaveUser()
        {
            unitOfWork.Commit();
        }
    }
}
